// pages/Main/mainIndex/mainIndex.js
var common = require('../../../utils/common.js')
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    array: [],
    content:[],
    ryid:""
  },
  bindPickerChange: function (e) {
    //console.log('picker发送选择改变，携带值为', e.detail.value) 
    this.setData({
      index: e.detail.value
    })
    this.list2();
    this.list3();
    this.list4();
  },

  /**
   * 生命周期函数--监听页面加载
   */

  mayTest:function(){
    wx.navigateTo({
      url: "../mayTest/mayTest?id=" + this.data.content[this.data.index].id
    });
  },
  alreadytest:function () {
    wx.navigateTo({
      url: "../alreadytest/alreadytest?id=" + this.data.content[this.data.index].id
    });
  }, 
  misTopic: function () {
     wx.navigateTo({
      url: "../misTopic/misTopic?id=" + this.data.content[this.data.index].id
    }); 
  },
  learnLog: function () {
    wx.navigateTo({
      url: "../learnLog/learnLog?id=" + this.data.content[this.data.index].id
    });
  },
  todayJob: function () {
    wx.navigateTo({
      url: "../todayJob/todayJob?id=" + this.data.content[this.data.index].id
    });
  },
  weaknowledge: function () {
    wx.navigateTo({
      url: "../weaknowledge/weaknowledge?id=" + this.data.content[this.data.index].id
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  onLoad: function (options) {
    console.log("22",options)
    let c = common.Getorgid();
    this.setData({
      ryid: options.id,
      orgid: c.orgid,
      userid: c.userid,
      index: 0  
    });
    this.list();
  },
  //6.2.1查询学生人员信息列表
  list: function () {
    // 第二步 传参
    let params = { "userid": this.data.userid, "orgid": this.data.orgid, "searchField": "departmentid", "searchValue": "92ef7278-0ebc-41e4-beaf-13dab650b0ed,077ba48e-76f8-4afd-8a84-67b4f2ed3762"}
    //第三步 调用接口
    businessLogic.QueryStudentlist(params, (res) => {
      console.log("6.2.1", res)
      //第五步 把获取的值，传入data
      var res = res.infos;
      for (let i = 0; i < res.length; i++) {
        if (res[i].id == this.data.ryid) {
          // console.log(i);
          var temp = res[0];
          res[0] = res[i];
          res[i] = temp;
        }
      }

      let child = new Array;
      for (let i = 0; i < res.length; i++) {
        child[i] = res[i].title;
        
      }
      console.log("11",this.data.ryid);
      this.setData({
        content: res,
         array: child
      });
      this.list2();
      this.list3();
      this.list4();
    });

  },
  //6.3.1查询收藏试题题数
  list2: function () {
    var i = this.data.index
    // 第二步 传参
    let params = { "userid": this.data.userid, "orgid": this.data.orgid, "searchField": "peopleid,iscollect", "searchValue": "" + this.data.content[i].id + ",1" }
    //第三步 调用接口
    businessLogic.ItemNumber(params, (res) => {
      //console.log("6.3.1", res)
      //第五步 把获取的值，传入data
      this.setData({
        shoucang: res.length
      });

    });

  },
  //6.3.2查询人员记录
  list3: function () {
    // 第二步 传参
    var i = this.data.index
    let params = { "userid": this.data.userid, "orgid": this.data.orgid, "searchField": "peopleid", "searchValue": "" + this.data.content[i].id + "" }
    //第三步 调用接口
    businessLogic.QueryRecords(params, (res) => {
      //console.log("6.3.2", res)
      //第五步 把获取的值，传入data
      this.setData({
        jilu: res.length

      });

    });

  },
  //6.3.3查询错题数
  list4: function () {
    // 第二步 传参
    var i = this.data.index
    let params = { "userid": this.data.userid, "orgid": this.data.orgid, "searchField": "peopleid,statemark,haspg", "searchValue": "" + this.data.content[i].id + ",0,1" }
    //第三步 调用接口
    businessLogic.WrongNumber(params, (res) => {
      console.log("6.3.3", res)
      //第五步 把获取的值，传入data
      this.setData({
        cuoti: res.length
      });
    });
  },
})


